package com.yanze.schoolinformation.view.my.person;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.yanze.schoolinformation.R;
import com.yanze.schoolinformation.app.App;
import com.yanze.schoolinformation.base.BaseActivity;
import com.yanze.schoolinformation.databinding.ActivityVpnBinding;
import com.yanze.schoolinformation.utils.DialogBuild;
import com.yanze.schoolinformation.utils.SPUtils;
import com.yanze.schoolinformation.utils.ToastUtils;

public class VpnActivity extends BaseActivity<ActivityVpnBinding> {

    private String address;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vpn);
        setTitle("内网IP地址");
        showContentView();
        address = (String) SPUtils.get(VpnActivity.this, "baseurl", "http://192.168.5.113");
        bindingView.tvAddress.setText(address);
    }

    public void modifyAddress(View view) {
        final EditText et = new EditText(this);
        et.setText(address);

        new AlertDialog.Builder(this).setTitle("修改")
                .setIcon(android.R.drawable.ic_dialog_info)
                .setView(et)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String input = et.getText().toString();
                        if ("".equals(input)) {
                            ToastUtils.show(VpnActivity.this, "请输入内容");
                        }else if (input.equals(address)){
                            ToastUtils.show(VpnActivity.this, "当前已经是该地址");
                        }else{
                            SPUtils.put(VpnActivity.this, "baseurl", input);
                            address = input;
                            bindingView.tvAddress.setText(address);
                            ToastUtils.show(VpnActivity.this,"修改成功");
                        }
                    }
                })
                .setNegativeButton("取消", null)
                .show();
    }

    /**
     * 入口
     */
    public static void start(Context context) {
        Intent intent = new Intent(context, VpnActivity.class);
        context.startActivity(intent);
    }
}
